import axios from 'axios';


// 登录请求方法
const loginreq = (method, url, params) => {
    return axios({
      method: method,
      url: url,
      // headers: {
      //     'Content-Type': 'application/x-www-form-urlencoded',
      // },
      headers: {
        'X-Requested-With': 'XMLHttpRequest',
        'Content-Type': 'application/json; charset=UTF-8'
      },

      data: {
        "password": params.password,
        "username": params.username
      },


    })

}


//captcha使用的方法
const captchareq = (method,url) =>{
  return axios({
    method:method,
    url:url,
    responseType:"blob"
  })
}
//获取登录用户信息的方法
const req_info = (method, url) => {
  return axios({
    method: method,
    url: url,
    headers:{
      "Authorization":JSON.parse(window.sessionStorage.getItem("Authorization-client"))
    }
    // headers: {
    //   "Authorization":localStorage.getItem("Authorization")
    // },
  })
};
//获取用户信息（分页）、
const reqPage = (method,url,params)=>{
  return axios({
    method: method,
    url: url+"?page="+params,
    headers: {
      Authorization: JSON.parse(window.sessionStorage.getItem("Authorization-client"))
    },
  })
};
//删除用户
const reqDeleteUser = (method,url,params)=>{
  return axios({
    method: method,
    url: url+"?id="+params,
    headers: {
      Authorization: JSON.parse(window.sessionStorage.getItem("Authorization-client"))
    },
  })
};
// 通用公用方法
// const req = (method, url, params) => {
//     return axios({
//       method: method,
//       url: url,
//       headers: {
//         Authorization: JSON.parse(window.sessionStorage.getItem("Authorization-client"))
//       },
//       data: {
//         params:params,
//         'Content-Type': 'application/json; charset=UTF-8'
//
//       }
//
//
//     })
// };
const req = (method, url, params) => {
  return axios({
    method: method,
    url: url,
    data: {

    "name": params.name,
    "password": params.password,
    "phone": params.phone,
    "sex": params.sex


    }


  })
};

//权限控制
const Permission = (method,url,params) =>{
  return axios({
    method: method,
    url: url+"?uid="+params,
    headers: {
      Authorization: JSON.parse(window.sessionStorage.getItem("Authorization-client"))
    },
})
};

//添加新用户
const Adduser = (method,url,params) => {
  return axios({
    method:method,
    url:url+"?username="+params.username+"&password="+params.password+"&address="+params.address+"&mation="+params.mation+"&phone="+params.phone+"&id="+params.id+"&headurl="+params.headers+"&file="+params.file,


  })
};
//查询数量
// const getNumber=(method,url) =>

//singer
const singer = (method,url) => {
  return axios({
    method:method,
    url:url,
    headers: {
      Authorization: JSON.parse(window.sessionStorage.getItem("Authorization-client"))
    },
  })
};

const number = (method,url) => {
  return axios({
    method:method,
    url:url,

  })
};

//文件上传
const file = (method,url,params) => {
  return axios({
    method:method,
    // headers: { "Content-Type": "multipart/form-data" },
    url:url,
    data:{
      file:params
    }
  })
}

export {
     loginreq,
     req,
     captchareq,
     req_info,
     reqPage,
     reqDeleteUser,
     Adduser,
     Permission,
     singer,
      file,
  number
}
